package com.car.controller;

import java.io.Reader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.car.entity.Citytable;
import com.car.entity.Code;
import com.car.entity.Lacar;
import com.car.entity.Laorder;
import com.car.entity.Provincialtable;
import com.car.entity.User;
import com.car.entity.Vehiclebrand;
import com.car.page.Page;
import com.car.service.CartableService;
import com.car.service.CartypeService;
import com.car.service.CodeService;
import com.car.service.DisplacementService;
import com.car.service.GrabTheService;
import com.car.service.LacarService;
import com.car.service.LaorderService;
import com.car.service.ProvincialtableService;
import com.car.service.UserService;
import com.car.service.VehiclebrandService;
import com.car.service.VehiclemotioncarService;
import com.car.vo.CartableVo;
import com.car.vo.GrabTheVo;
import com.car.vo.VehiclemotioncarVo;

@Controller
@RequestMapping("/lahuocar")
public class LahuocarController {
	@Autowired
	LacarService lacar;
	@Autowired
	LaorderService laorder;
	@Autowired
	UserService user;
@RequestMapping("tolahuocar")
public String tocar(Model model) {
	List<Lacar> listcar=lacar.selectall();
	model.addAttribute("listcar", listcar);
	return "lahuocar";
}

@RequestMapping("/addcar")
public String toaddcar(@ModelAttribute("form")Lacar lacars) {
	int add=lacar.insertcar(lacars);
	if(add!=0) {
		return "tolahuocar";
	}
return "lahuocar";
}
@ResponseBody
@RequestMapping("delcar")
public int todelcar(int id) {
	int del=lacar.delcar(id);
	return del;
}
@ResponseBody
@RequestMapping("updcar")
public Lacar toupdcar(int id) {
	Lacar car=lacar.selectlist(id);
	return car;
}
@RequestMapping("upd")
public String toupd(Lacar lacars) {
int upd=lacar.updcar(lacars);
return "tolahuocar";
}

@RequestMapping("tolahuoorder")
public String tolahuoorder(Model model) {
	List<Laorder> orderlist=laorder.selectall();
	List<Lacar> carlist=lacar.selectall();
	List<User> userlist=user.selectAll();
	model.addAttribute("orderlist",orderlist);
	model.addAttribute("carlist", carlist);
	model.addAttribute("userlist", userlist);
	return "lahuoorder";
	
}

@RequestMapping("orderselect")
public String toorderselect(int carid,int state,Model model) {
	List<Laorder> orderlist=laorder.selectstate(carid, state);
	List<Lacar> carlist=lacar.selectall();
	List<User> userlist=user.selectAll();
	model.addAttribute("orderlist",orderlist);
	model.addAttribute("carlist", carlist);
	model.addAttribute("userlist", userlist);
	return "lahuoorder";
}

@ResponseBody
@RequestMapping("orderupdsel")
public Laorder toorderupdsel(int id) {
	Laorder ordersel=laorder.orderupdsel(id);
	return ordersel;
			
}
@RequestMapping("stateupd")
public String tostateupd(int id) {
	int upd=laorder.stateupd(id);
	return "tolahuoorder";
}
}